﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Enterprise.Utility;
using Enterprise.Model;
using Enterprise.Bll.Contract;

namespace Enterprise.Web
{
    public partial class NewsList : System.Web.UI.Page
    {
        private static string _templateFileName = "NewsList.html";
        private string[] cssFileUrlList;
        private int currentPage;
        private int pageSize=5;
        INews inews = Factorys.GetBllImplement.GetNews();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["page"] != null)
                currentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            else
                currentPage = 1;
            cssFileUrlList = SiteUtility.GetCssFileUrlList();
            DataBinds();
        }
        protected void DataBinds()
        {
            IEnumerable<News> noticeList =BindNotices();
            var obj = new VelocityHelper("~/Template", System.Text.Encoding.GetEncoding("UTF-8"));
            int totalRecord = 0;
            int totalPage = 0;
            IEnumerable<News> newList = ModelConvertHelper<News>.ToModels(inews.GetNewList(currentPage, pageSize, out totalPage, out totalRecord, ""));
            Pages pages = new Pages();
            pages.SetPage(obj,totalRecord,totalPage,currentPage, pageSize);

            obj.Put("newlist", newList);
            obj.Put("noticelist",noticeList);
            obj.Put("CssFileUrlList", cssFileUrlList);
            obj.Put("resRootPath", SiteUtility.GetResRootPath());
            obj.Display(_templateFileName);
        }
        /// <summary>
        /// 公告
        /// </summary>
        protected IEnumerable<News> BindNotices()
        {
            return ModelConvertHelper<News>.ToModels(inews.GetArticleList(1, 5));
        }
    }
}
